package com.hospital.login.controller;

import com.hospital.login.entity.AdminUser;
import com.hospital.login.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping(value = "/login")
public class LoginController {

    @Autowired
    LoginService loginService;

    @RequestMapping(value = "/submit",method = RequestMethod.POST)
    public String loginDemo(@RequestParam("userNum")String userNum,
                            @RequestParam("password")String pwd,
                            HttpSession session){
        AdminUser adminUser = new AdminUser();
        if (loginService.loginJudge(userNum,pwd).equals(1)){
            session.setAttribute("adminUser",adminUser);
            return "redirect:/html/main.html";
        }
        return "redirect:/html/login.html";
    }

    @GetMapping(value = "/demo",produces = "application/json;charset=utf-8")
    @ResponseBody
    public String demo(){
        return loginService.getAll();
    }

}
